package com.jeegit.ecms.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jeegit.common.annotation.Log;
import com.jeegit.common.enums.BusinessType;
import com.jeegit.ecms.domain.CmsBanners;
import com.jeegit.ecms.service.ICmsBannersService;
import com.jeegit.common.core.controller.BaseController;
import com.jeegit.common.core.domain.AjaxResult;
import com.jeegit.common.utils.poi.ExcelUtil;
import com.jeegit.common.core.page.TableDataInfo;

/**
 * 首页横幅Controller
 * 
 * @author jeegit
 * @date 2022-07-05
 */
@Controller
@RequestMapping("/ecms/banners")
public class CmsBannersController extends BaseController
{
    private String prefix = "ecms/banners";

    @Autowired
    private ICmsBannersService cmsBannersService;

    @RequiresPermissions("ecms:banners:view")
    @GetMapping()
    public String banners()
    {
        return prefix + "/banners";
    }

    /**
     * 查询首页横幅列表
     */
    @RequiresPermissions("ecms:banners:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CmsBanners cmsBanners)
    {
        startPage();
        List<CmsBanners> list = cmsBannersService.selectCmsBannersList(cmsBanners);
        return getDataTable(list);
    }

    /**
     * 导出首页横幅列表
     */
    @RequiresPermissions("ecms:banners:export")
    @Log(title = "首页横幅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CmsBanners cmsBanners)
    {
        List<CmsBanners> list = cmsBannersService.selectCmsBannersList(cmsBanners);
        ExcelUtil<CmsBanners> util = new ExcelUtil<CmsBanners>(CmsBanners.class);
        return util.exportExcel(list, "首页横幅数据");
    }

    /**
     * 新增首页横幅
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存首页横幅
     */
    @RequiresPermissions("ecms:banners:add")
    @Log(title = "首页横幅", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CmsBanners cmsBanners)
    {
        return toAjax(cmsBannersService.insertCmsBanners(cmsBanners));
    }

    /**
     * 修改首页横幅
     */
    @RequiresPermissions("ecms:banners:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CmsBanners cmsBanners = cmsBannersService.selectCmsBannersById(id);
        mmap.put("cmsBanners", cmsBanners);
        return prefix + "/edit";
    }

    /**
     * 修改保存首页横幅
     */
    @RequiresPermissions("ecms:banners:edit")
    @Log(title = "首页横幅", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CmsBanners cmsBanners)
    {
        return toAjax(cmsBannersService.updateCmsBanners(cmsBanners));
    }

    /**
     * 删除首页横幅
     */
    @RequiresPermissions("ecms:banners:remove")
    @Log(title = "首页横幅", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cmsBannersService.deleteCmsBannersByIds(ids));
    }
}
